package com.yycx.module.bus.provider.handler.haiying.tasktodo.settle.fapiao;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.UpdateInterceptor;
import com.yycx.common.mybatis.query.CriteriaUpdate;
import com.yycx.module.bus.client.entity.BusInvoiceunit;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.entity.hy.BusHyorderInovice;
import com.yycx.module.bus.provider.service.BusInvoiceunitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 发票保存处理器
 *
 * @author zyf
 */
@Component
public class HyInvoiceNoSavePaymentHandler implements UpdateInterceptor<BusHyorderInovice> {

    @Autowired
    private BusInvoiceunitService invoiceunitService;

    @Override
    public void prepare(CriteriaUpdate cs, EntityMap entityMap, BusHyorderInovice payment) {

    }

    @Override
    public void complete(CriteriaUpdate cs, EntityMap params, BusHyorderInovice entity) {
        Date contractDate = cs.getDate("contractDate");
        Long invoiceUnitId = entity.getInvoiceUnitId();
        BusInvoiceunit invoiceunit = invoiceunitService.getById(invoiceUnitId);
        if (FlymeUtils.isNotEmpty(invoiceunit) && FlymeUtils.isNotEmpty(contractDate)) {
            invoiceunit.setContractDate(contractDate);
            invoiceunitService.updateById(invoiceunit);
        }
    }

}
